export default class Songs {
	constructor({id,mid,singer,name,album,duration,image,url}){
		this.id = id
		this.mid = mid
		// 歌唱者
		this.singer = singer

		this.name = name

		this.album = album

		this.duration = duration

		this.image = image

		this.url = url
	}
}

export function createSong(obj) {
	// console.log(obj)
	return new Songs({
		id:obj.songid,
		mid:obj.songmid,
		//singer可能有多个，通过filterSinger方法将歌手的名字以&连起来的字符串返回回来
		singer:filterSinger(obj.singer),
		name:obj.songname,
		album:obj.albumname,
		duration:obj.interval,
		image:`https://y.gtimg.cn/music/photo_new/T002R300x300M000${obj.albummid}.jpg?max_age=2592000`,
		url:`http://dl.stream.qqmusic.qq.com/C400${obj.songmid}.m4a?guid=2872000732&vkey=52C9D8202C968B12ACDB09529277329E789E07DD32F78689E0D3EDB51A07593003C2318AF3E00D175D9ED030DD84DFD8BFB8A443FD0DC120&uin=0&fromtag=38`
	})
}

//这个方法将有歌手的名字转化成以&连起来的字符串
function filterSinger(singer){
	var ret = [];
	if(!singer){
		return '';
	}
	singer.forEach((item)=>{
		ret.push(item.name)
	})
	return ret.join("&")
}